package com.zycfc.zsf.boot.logback.core;

import java.io.*;
import com.zycfc.zsf.boot.logback.consts.*;
import com.zycfc.zsf.boot.util.net.*;
import com.zycfc.zsf.boot.util.text.*;
import com.zycfc.zsf.boot.common.context.*;
import org.slf4j.*;

public class BizTranInf implements Serializable
{
    private static final Logger log;
    private static final long serialVersionUID = 1L;
    private String flowId;
    private String bizId;
    private String tranCd;
    private String idNo;
    private String name;
    private String channelNo;
    private String ip;
    private String sendTime;
    private String receiveTime;
    private String requestData;
    private String responseData;
    private String respCode;
    private String exeSts;
    private String grayscaleFlag;
    
    @Override
    public String toString() {
        return LogTypeEnum.BIZTRAN + "@@@" + this.flowId + "#@%@#" + this.bizId + "#@%@#" + this.tranCd + "#@%@#" + this.idNo + "#@%@#" + this.name + "#@%@#" + this.channelNo + "#@%@#" + this.ip + "#@%@#" + this.sendTime + "#@%@#" + this.receiveTime + "#@%@#" + this.requestData + "#@%@#" + this.responseData + "#@%@#" + this.exeSts + "#@%@#" + this.respCode + "#@%@#" + this.grayscaleFlag;
    }
    
    public BizTranInf() {
        this.dealGrayscale();
    }
    
    public BizTranInf(final BizTranBuilder builder) {
        this.flowId = builder.getFlowId();
        this.bizId = builder.getBizId();
        this.tranCd = builder.getTranCd();
        this.idNo = builder.getIdNo();
        this.name = builder.getName();
        this.channelNo = builder.getChannelNo();
        this.ip = NetUtils.getLocalHost();
        this.sendTime = builder.getSendTime();
        this.receiveTime = builder.getReceiveTime();
        this.requestData = builder.getRequestData();
        this.responseData = builder.getResponseData();
        this.exeSts = builder.getExeSts();
        this.respCode = builder.getRespCode();
        this.dealGrayscale();
    }
    
    public BizTranInf(final String flowId, final String bizId, final String tranCd, final String idNo, final String name, final String channelNo, final String sendTime, final String receiveTime, final String requestData, final String responseData, final String exeSts) {
        this.flowId = flowId;
        this.bizId = bizId;
        this.tranCd = tranCd;
        this.idNo = idNo;
        this.name = name;
        this.channelNo = channelNo;
        this.ip = NetUtils.getLocalHost();
        this.sendTime = sendTime;
        this.receiveTime = receiveTime;
        this.requestData = requestData;
        this.responseData = responseData;
        this.exeSts = exeSts;
        this.dealGrayscale();
    }
    
    public void setException(final Throwable e) {
        final String excpetionMsg = e.getMessage();
        if (StringUtils.isEmptyAll(excpetionMsg)) {
            this.respCode = "Z999999";
            return;
        }
        final String[] array = excpetionMsg.split("##@##");
        if (array.length == 1) {
            final String msg = array[0];
            final int end = Math.min(msg.length(), 20);
            this.respCode = msg.substring(0, end);
        }
        else if (array.length >= 2) {
            this.respCode = array[0];
        }
    }
    
    private void dealGrayscale() {
        try {
            final String str = ZsfRootContext.get("grayscaleFlag");
            if ("true".equals(str)) {
                this.grayscaleFlag = "1";
            }
            else {
                this.grayscaleFlag = "0";
            }
            if (StringUtils.isNotEmpty(str)) {
                ZsfRootContext.remove("grayscaleFlag");
            }
        }
        catch (Exception e) {
            BizTranInf.log.error("dealGrayscale-Exception:", (Throwable)e);
        }
    }
    
    public void setFlowId(final String flowId) {
        this.flowId = flowId;
    }
    
    public void setBizId(final String bizId) {
        this.bizId = bizId;
    }
    
    public void setTranCd(final String tranCd) {
        this.tranCd = tranCd;
    }
    
    public void setIdNo(final String idNo) {
        this.idNo = idNo;
    }
    
    public void setName(final String name) {
        this.name = name;
    }
    
    public void setChannelNo(final String channelNo) {
        this.channelNo = channelNo;
    }
    
    public void setIp(final String ip) {
        this.ip = ip;
    }
    
    public void setSendTime(final String sendTime) {
        this.sendTime = sendTime;
    }
    
    public void setReceiveTime(final String receiveTime) {
        this.receiveTime = receiveTime;
    }
    
    public void setRequestData(final String requestData) {
        this.requestData = requestData;
    }
    
    public void setResponseData(final String responseData) {
        this.responseData = responseData;
    }
    
    public void setRespCode(final String respCode) {
        this.respCode = respCode;
    }
    
    public void setExeSts(final String exeSts) {
        this.exeSts = exeSts;
    }
    
    public void setGrayscaleFlag(final String grayscaleFlag) {
        this.grayscaleFlag = grayscaleFlag;
    }
    
    public String getFlowId() {
        return this.flowId;
    }
    
    public String getBizId() {
        return this.bizId;
    }
    
    public String getTranCd() {
        return this.tranCd;
    }
    
    public String getIdNo() {
        return this.idNo;
    }
    
    public String getName() {
        return this.name;
    }
    
    public String getChannelNo() {
        return this.channelNo;
    }
    
    public String getIp() {
        return this.ip;
    }
    
    public String getSendTime() {
        return this.sendTime;
    }
    
    public String getReceiveTime() {
        return this.receiveTime;
    }
    
    public String getRequestData() {
        return this.requestData;
    }
    
    public String getResponseData() {
        return this.responseData;
    }
    
    public String getRespCode() {
        return this.respCode;
    }
    
    public String getExeSts() {
        return this.exeSts;
    }
    
    public String getGrayscaleFlag() {
        return this.grayscaleFlag;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)BizTranInf.class);
    }
}
